﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Routing;
using System.Web.Mvc;
using System.Web.Mvc.Html;

namespace Bzure.Mvc.Html
{
    public static class ImageHelper
    {
        public static string ThemeImage(this HtmlHelper helper, string url,string id, string alternateText, object htmlAttributes)
        {
            return helper.Image(Actor.Public.Url().ThemeContent(url),id,alternateText ,htmlAttributes);
        }
        public static string ThemeAreaImage(this HtmlHelper helper, string AreaName, string url,string id, string alternateText, object htmlAttributes)
        {
            return helper.Image(Actor.Public.Url().ThemeAreaContent(AreaName, url), id, alternateText, htmlAttributes);
        }
        public static string GenericThemeImage(this HtmlHelper helper, string url,string id, string alternateText, object htmlAttributes)
        {
            return helper.Image(Actor.Public.Url().GenericThemeContent(url), id, alternateText, htmlAttributes);
        }
        public static string GenericThemeAreaImage(this HtmlHelper helper, string AreaName, string url,string id, string alternateText, object htmlAttributes)
        {
            return helper.Image(Actor.Public.Url().GenericThemeAreaContent(AreaName, url), id, alternateText, htmlAttributes);
        }
        static string Image(this HtmlHelper helper, string url, string id, string alternateText, object htmlAttributes)
        {
            // Create tag builder
            var builder = new TagBuilder("img");

            // Create valid id
            builder.GenerateId(id);

            // Add attributes
            builder.MergeAttribute("src", url);
            builder.MergeAttribute("alt", alternateText);
            builder.MergeAttributes(new RouteValueDictionary(htmlAttributes));

            // Render tag
            return builder.ToString(TagRenderMode.SelfClosing);
        }
    }
}
